<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">活动标题</label>
									<div class="layui-input-inline">
										<input type="text" name="title" placeholder="请输入活动标题" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">报名费用</label>
									<div class="layui-input-inline">
										<input type="text" name="fee" placeholder="请输入报名费用" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">活动开始时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="starttime" class="layui-input" id="starttime" autocomplete="off" placeholder="活动开始时间：">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">活动结束时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="finishtime" class="layui-input" id="finishtime" autocomplete="off" placeholder="活动结束时间：">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">活动报名开始时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="signUpStarttime" class="layui-input" id="signUpStarttime" autocomplete="off" placeholder="活动开始时间：">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">活动报名结束时间：</label>
									<div class="layui-input-inline">
										<input type="text" name="signUpFinishtime" class="layui-input" id="signUpFinishtime" autocomplete="off" placeholder="活动结束时间：">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">活动图片</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal" onclick="choose(0)">上传图片</button>
									<ul class="show_img_ul" id="img"></ul>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">活动简介</label>
									<div class="layui-input-block">
										<textarea class="layui-textarea layui-hide" name="intro" lay-verify="intro" id="demo_editor"></textarea>
									</div>
								</div>
							</div>
						</div>
					</div> 
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;"> 
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="https://api.lishuahuoban.cn/layuiadmin/city.data.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id')
			}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				tinymce: '../tinymce/tinymce',
				index: 'lib/index' ,//主入口模块
				location: 'location/location',
			}).use(['index', 'form', 'laytpl', 'laydate','tinymce'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					tinymce = layui.tinymce,
					form = layui.form;

				var area_cn_arr = [],
					img_arr2 = [];
					img_arr0 = [];
				var edit = tinymce.render({
					elem: "#demo_editor",
					height: 600
				});
				laydate.render({
					elem: '#starttime',
					type: 'datetime'
				});
				laydate.render({
					elem: '#finishtime',
					type: 'datetime'
				});
				laydate.render({
					elem: '#signUpStarttime',
					type: 'datetime'
				});
				laydate.render({
					elem: '#signUpFinishtime',
					type: 'datetime'
				});
				agent_type_show('radio')
				on_off_show('radio')
//				initroledatashow('option')
//				initsite_unionshow('option')
				if (_data.id) {
					initdata();
				}
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.img = img_arr0.join(',');
					_data.intro = edit.getContent();
					//_data.area_cn = area_cn_arr.join(',')

					layer.confirm('确定要提交数据？', function() {
						loading();
						if(_data.id){
							submitdata(_data,server.paid_activities_edit);
						}else{
							delete _data.id;
							submitdata(_data,server.paid_activities_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});
				function submitdata(_data,_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
								layer.closeAll('loading');
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: 'up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}

				window.getimg = function(data, type) {
					console.log(data);
					if(data) {
						switch(type) {
							case '0':
								createli(data, 'img', type)
								break;
							default:
								break;
						}
					}
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					layer.confirm('确定要删除图片？', function(index) {
						switch(_type) {
							case '0':
								img_arr0.splice(i, 1)
								break;
							default:
								break;
						}
						$(_self).parent().remove();
						layer.close(index)
					}, function() {
						layer.msg('取消操作');
					});
				}

				function createli(data, dom, type) {
					var lihtml = '';
					switch(type) {
						case '0':
							if(data.indexOf(',') == -1) {
								img_arr0.splice(0, 1, data)
							} else {
								for(var i = 0; i < data.split(',').length; i++) {
									img_arr0.push(data.split(',')[i])
								}
							}
							for(var i = 0; i < img_arr0.length; i++) {
								lihtml += '<li class="show_img_li1">' +
									'<img src=' + img_arr0[i] + ' >' +
									'<p onclick="delimg(' + i + ',0,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}

				function initdata() {
					$.get(server.paid_activities_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.paid_activities
								data.data.img ? createli(data.data.img, 'img', '0') : '',
								edit.setContent(data.data.intro)
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
			}
			});
		</script>
	</body>

</html>